package com.wangyadong.hobby.schedule.jobtask.teststack;


/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2018/9/2519:28
 **/
public class ArrayStack<E> implements Stack<E> {
    private static final int CAPACITY = 1000;
    E[] data;
    private int size = -1;

    public ArrayStack() {
        data = (E[]) new Object[CAPACITY];
    }

    public ArrayStack(int capaCity) {
        data = (E[]) new Object[capaCity];
    }

    @Override
    public E pop() {
        if (isEmpty()) {
            return null;
        }
        E datum = data[size];
        size--;
        return datum;
    }

    @Override
    public void push(E e) {
        if (data.length == size)
            throw new RuntimeException("");
        data[++size] = e;
    }

    @Override
    public E top() {
        if (size == -1)
            return null;
        else
            return data[size];
    }

    @Override
    public int size() {
        return size + 1;
    }

    @Override
    public boolean isEmpty() {
        return size() == -1;
    }


    public static void main(String[] args) {
        Stack stack = new ArrayStack();
        stack.push(33);
        stack.push(34);
        System.out.println(stack.pop());
    }
}
